package com.ying.service.impl;

import com.ying.domain.UserOne;
import com.ying.domain.UserTwo;
import com.ying.service.IUserOneService;
import com.ying.service.IUserTwoService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author liujunjie
 * @Description description
 * @Date 2024-10-08 19:06
 **/
@Service
@RequiredArgsConstructor
public class TxService {
    private final IUserOneService userOneService;
    private final IUserTwoService userTwoService;

    @Transactional
    public void requiedAndrequired(UserOne userOne, UserTwo userTwo) {
        userOneService.required(userOne);
        userTwoService.required(userTwo);
    }

    @Transactional
    public void requiedAndrequiredExcepection(UserOne userOne, UserTwo userTwo) {
        userOneService.required(userOne);
        userTwoService.requiredException(userTwo);
    }

    public void notransaction_exception_required_required(UserOne userOne, UserTwo userTwo) {
        userOneService.required(userOne);
        userTwoService.required(userTwo);
        throw new RuntimeException();
    }

    @Transactional
    public void transaction_exception_required_required(UserOne userOne, UserTwo userTwo) {
        userOneService.required(userOne);
        userTwoService.required(userTwo);
        throw new RuntimeException();
    }


    @Transactional
    public void commonTest(UserOne userOne, UserTwo userTwo) {
        userOneService.required(userOne);
        common(userTwo);

    }

    public void common(UserTwo userTwo) {
        userTwoService.required(userTwo);
//        throw new RuntimeException();
    }


}
